import React, { Component, createRef } from "react";

class App extends Component {
  box = createRef();
  ipt = createRef();

  fn = () => {
    console.log(this.ipt.current.value);
  };

  render() {
    return (
      <>
        <h2>使用ref获取dom节点</h2>
        <div className="box" ref={this.box}>
          box
        </div>
        <input type="text" ref={this.ipt} />
        <button onClick={this.fn}>btn</button>
      </>
    );
  }

  componentDidMount() {
    console.log(this.box.current);
  }
}

export default App;
